package lk.icta.common.entity;

import lk.icta.common.AppConstants;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(schema = "COMMON_RAIL")
@NamedQueries({
        @NamedQuery(name = "findAllDistricts", query = "SELECT d FROM District d"),
        @NamedQuery(name = "get.district.by.code", query = "SELECT d FROM District d " + "WHERE d.code =:districtId")
})
public class District implements Serializable {
    /**
     * This is a system generated unique key
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    /**
     * This is the standard District ID as per the location code database
     */
    @Column(updatable = false, unique = true, nullable = false)
    private int code;

    /**
     * The relationship to Province of which this District belongs
     */
    @ManyToOne
    @JoinColumn(nullable = false, updatable = false)
    private Province province;

    @Column(nullable = false, unique = true, updatable = false)
    private String siDistrictName;
    @Column(nullable = false, unique = true, updatable = false)
    private String enDistrictName;
    @Column(nullable = false, unique = true, updatable = false)
    private String taDistrictName;

    @Column(columnDefinition = "smallint not null default 1")
    private boolean active;

    public District() {
    }

    public District(int districtId, Province province, String siDistrictName, String enDistrictName, String taDistrictName, boolean active) {
        this.id = districtId;
        this.province = province;
        this.siDistrictName = siDistrictName;
        this.enDistrictName = enDistrictName;
        this.taDistrictName = taDistrictName;
        this.active = active;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Province getProvince() {
        return province;
    }

    public void setProvince(Province province) {
        this.province = province;
    }

    public String getSiDistrictName() {
        return siDistrictName;
    }

    public void setSiDistrictName(String siDistrictName) {
        this.siDistrictName = siDistrictName;
    }

    public String getEnDistrictName() {
        return enDistrictName;
    }

    public void setEnDistrictName(String enDistrictName) {
        this.enDistrictName = enDistrictName;
    }

    public String getTaDistrictName() {
        return taDistrictName;
    }

    public void setTaDistrictName(String taDistrictName) {
        this.taDistrictName = taDistrictName;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public String getDistrictNameByLanguage(String language) {
        String districtName = "";
        if (AppConstants.ENGLISH.equals(language)) {
            districtName = getEnDistrictName();
        } else if (AppConstants.SINHALA.equals(language)) {
            districtName = getSiDistrictName();
        } else if (AppConstants.TAMIL.equals(language)) {
            districtName = getTaDistrictName();
        }

        return districtName;
    }
}
